import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;

@WebServlet("/postParameterJson")
public class PostParameterjson extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("application/json; charset=utf-8");
        // 这里是表名响应返回的数据格式为json
        String body = readBody(req);
        System.out.println(body);
        resp.getWriter().write(body);
    }

    private String readBody(HttpServletRequest req) throws IOException {
        int contentLength = req.getContentLength();
        byte[] buffer = new byte[contentLength];
        //buffer = req.get
        InputStream inputStream = req.getInputStream();
        inputStream.read(buffer);
        // 这个意思难道是从键盘获取输入吗
        return new String(buffer, "utf-8");
    }

}
